import os, string, sys;
def mkdir(path):
    if(sys.platform.find("linux")<0):
        path = toWinFile(path);
#        tup = string.split(path, "\\");
#        basePath = tup[0];
        if(os.path.exists(path)== False):
            os.makedirs(path);
#        for i in range(1,len(tup)):
#            basePath = os.path.join(basePath, tup[i])
#            basePath = rp(basePath);
#            try:
#                if(os.path.exists(basePath) == False):
#                    print "mkdir " + basePath
#    #                os.system("mkdir " + basePath);
#                    os.mkdir(basePath)
#            except:
#                pass;
        
    else:
        if(os.path.exists(path)== False):
            os.makedirs(path);
#        path = path.replace("\\", '/')
#        tup = string.split(path, "/");
#    #    print tup
#        basePath = tup[0];
#        if(len(tup[0]) == 0):
#            basePath = "/";
#    
#        for i in range(1,len(tup)):
#    #        print basePath
#            basePath = os.path.join(basePath, tup[i])
#            basePath = rp(basePath);
#            try:
#                if(os.path.exists(basePath) == False):
#                    print "mkdir " + basePath
#    #                os.system("mkdir " + basePath);
#                    os.mkdir(basePath)
##                print "mkdir " + basePath;
##                os.system("mkdir " + basePath);
#            except:
#                pass;

def rt(tPath):
    if(tPath[len(tPath)-1]=='/'):
        tPath = tPath[0:len(tPath)-1];
    return tPath;

def rp(path):
    path = path.replace('\\', '/')
    return path

def toLinux(path):
    if(path.find("/cygdrive")>=0):
        path = path.replace("/cygdrive/", "");
        path = path[1:]; #skip disk label
    elif(path.find("/")==0):
        return path;
    return path

def toCygwin(path):
    path = rp(path);
    if(path.find("/cygdrive")>=0):
        return path
    if (path.find(":") >= 0 and sys.platform == "win32") :
        diskpath = path[0:path.find(":")];
#        print diskpath
        diskpath = "/cygdrive/" + diskpath;
        diskpath = diskpath + path[path.find(":")+1:]
        return diskpath
    if(path.find(":") <0 and sys.platform == "win32"):
        path = "/cygdrive/c" + path;
    if(path.find(' ')>=0):
        print path;
    return path

def toWinFile(path):
#    if(path.find("/") == 0 and sys.platform == "win32" and path.find("cygdrive")<0):
#        path = toCygwin(path)
    if(sys.platform == "win32" and path.find("cygdrive")>=0):
        path = toCygwin(path);
        path = path.replace("/cygdrive/", "");
        disk = path[0];
        path = path[2:].replace("/", "\\");
#        path = disk + ":\\" + "cygwin\\" + path
        path = disk + ":\\" + path
        return path
    path = rp(path).replace("/", "\\");
    return path;

def fm(path):
    if(sys.platform == "win32"):
        return toWinFile(path);
    if(sys.platform.find("linux")>=0):
        return toLinux(path);
    
if __name__ == "__main__":
    filename = "/cygdrive/c/var/scratch/sshen/test_result/1a1/10000_1a1_1_siqi-PC_log.txt";
    path = toWinFile(filename)
    print path